package com.cyys.common.em;

import java.util.HashMap;
import java.util.Map;

public enum WhetherEnum implements BaseEnum<WhetherEnum, Integer>{
		yes(1,"是"), no(0,"否");
		// 成员变量
		private Integer index;
		private String name;
		
		private static final Map<Integer, WhetherEnum> CODE_MAP = new HashMap<Integer, WhetherEnum>();
		private static final Map<String, WhetherEnum> NAME_MAP = new HashMap<String, WhetherEnum>();

        static {
            for (WhetherEnum typeEnum : WhetherEnum.values()) {
                CODE_MAP.put(typeEnum.getIndex(), typeEnum);
                NAME_MAP.put(typeEnum.getName(), typeEnum);
            }
        }
        
        public static WhetherEnum getEnum(Integer index) {
            return CODE_MAP.get(index);
        }
        
        @SuppressWarnings("unlikely-arg-type")
		public static WhetherEnum getEnumByName(String name) {
            return CODE_MAP.get(name);
        }

		
		// 构造方法
		private WhetherEnum(Integer index,String name) {
			this.name = name;
			this.index = index;
		}
		//覆盖方法
		@Override
		public String toString() {
			return this.index+"_"+this.name;
		}
		
		// 普通方法  
	    public static String getName(int index) {  
	        for (WhetherEnum c : WhetherEnum.values()) {  
	            if (c.getIndex() == index) {  
	                return c.name;  
	            }  
	        }  
	        return null;  
	    }
	    public static Integer getIndex(String name) {
			for (WhetherEnum c : WhetherEnum.values()) {  
	            if (c.getName().equals(name)) {  
	                return c.index;  
	            }  
	        }  
	        return null;
		}
	    
	    public Integer getIndex() {
			return index;
		}
	    
	    public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		
		public void setIndex(int index) {
			this.index = index;
		}
}
